/*
 *      Created on: March 9, 2011
 *      Author: topcoder
 */
#include <Unit.h>
#include <sstream>

Unit::Unit(unsigned int ratio, string name):ratio_m(ratio),name_m(name){}
Unit::~Unit(){}

unsigned long Unit::convertToBase(unsigned long quantity)const {return (ratio_m * quantity);}
unsigned long Unit::getRemainder(unsigned long quantity)const {return (quantity%ratio_m);}
bool Unit::operator <= (const Unit& unit)const {return (ratio_m <= unit.ratio_m);}

string Unit::outputFormat(unsigned long quantity)const 
{
    ostringstream tempString;
    (quantity/ratio_m)?(tempString << " " << quantity/ratio_m << " " << name_m):(tempString << "");
    return tempString.str();
}
